package com.kefu.call.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.kefu.call.model.AgentServiceLevelConfig;
import com.kefu.call.service.CallServiceLevelConfigService;
import com.kefu.call.vo.ServiceLevelConfigQueryVo;
import com.kefu.common.context.KefuContext;
import com.kefu.common.controller.AbstractBaseController;
import com.kefu.common.result.Result;
import com.kefu.common.result.ResultGenerator;
import com.kefu.common.vo.DeleteVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "呼叫满意度设置")
@RestController
@RequestMapping("call/serviceLevelConfig")
public class CallServiceLevelConfigController extends AbstractBaseController {

    @Autowired
    CallServiceLevelConfigService callServiceLevelConfigService;


    @PostMapping("/list")
    @ApiOperation(value = "查询")
    public Result<List<AgentServiceLevelConfig>> listConfig(@RequestBody ServiceLevelConfigQueryVo queryVo) {
        List<AgentServiceLevelConfig> list = callServiceLevelConfigService.list(Wrappers.lambdaQuery(AgentServiceLevelConfig.class)
                        .eq(AgentServiceLevelConfig::getIvrId, queryVo.getIvrId())
                .eq(AgentServiceLevelConfig::getCompany, KefuContext.getTid()));
        return ResultGenerator.genSuccessResult(list);
    }

    @PostMapping("/add")
    @ApiOperation(value = "增加")
    public Result<String> add(@Validated @RequestBody AgentServiceLevelConfig info) {
        logger.info("增加满意度等级设置:{}", info);

        info.setCompany(KefuContext.getTid());
        callServiceLevelConfigService.save(info);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改")
    public Result<String> update(@Validated @RequestBody AgentServiceLevelConfig info) {
        logger.info("修改满意度等级设置:{}", info);

        callServiceLevelConfigService.update(info);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除")
    public Result<String> delete(@Validated @RequestBody DeleteVo delete) {
        logger.info("删除满意度等级:{}", delete);

        callServiceLevelConfigService.deleteById(delete.getId());
        return ResultGenerator.genSuccessResult();
    }
}
